<html>
<!-- =====================================================================

  File:      Generated file for Adventure Works Cycles Storefront Sample
  Summary:   Self-documentation for application
  Date:	     June 16, 2003

=====================================================================

  This file is part of the Microsoft SQL Server Code Samples.
  Copyright (C) 2003 Microsoft Corporation.  All rights reserved.

This source code is intended only as a supplement to Microsoft
Development Tools and/or on-line documentation.  See these other
materials for detailed information regarding Microsoft code samples.

THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

======================================================= -->
<head>
  <link rel=stylesheet href=style.css>
</head>
<body>
<div class=SourcePanel style="font-size:12">
<pre style="background-color:white">
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Collections</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">ComponentModel</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Data</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Drawing</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Web</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Web</span>.<span style="color: #2040a0">UI</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Web</span>.<span style="color: #2040a0">UI</span>.<span style="color: #2040a0">WebControls</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Web</span>.<span style="color: #2040a0">UI</span>.<span style="color: #2040a0">HtmlControls</span><span style="color: #4444FF">;</span>
<span style="color: #0000FF"><strong>using</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Globalization</span><span style="color: #4444FF">;</span>

<span style="color: #008000">/* =====================================================================

  File:      ReviewAdd.aspx.cs for Adventure Works Cycles Storefront Sample
  Summary:   Collects user comments about a product and saves them
  Date:	     June 16, 2003

---------------------------------------------------------------------

  This file is part of the Microsoft SQL Server Code Samples.
  Copyright (C) Microsoft Corporation.  All rights reserved.

This source code is intended only as a supplement to Microsoft
Development Tools and/or on-line documentation.  See these other
materials for detailed information regarding Microsoft code samples.

THIS CODE AND INFORMATION ARE PROVIDED &quot;AS IS&quot; WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

======================================================= */</span>

<span style="color: #0000FF"><strong>namespace</strong></span> <span style="color: #2040a0">Microsoft</span>.<span style="color: #2040a0">Samples</span>.<span style="color: #2040a0">SqlServer</span> <span style="color: #4444FF"><strong>{</strong></span>

    <span style="color: #0000FF"><strong>public</strong></span> <span style="color: #2040a0">partial</span> <span style="color: #0000FF"><strong>class</strong></span> <span style="color: #2040a0">ReviewAdd</span> <span style="color: #4444FF">:</span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Web</span>.<span style="color: #2040a0">UI</span>.<span style="color: #2040a0">Page</span>
    <span style="color: #4444FF"><strong>{</strong></span>

    
<span style="color: #008000">//         public ReviewAdd() {</span>
<span style="color: #008000">//             Page.Init += new System.EventHandler(Page_Init);</span>
<span style="color: #008000">//         }</span>

        <span style="color: #008000">//*******************************************************</span>
        <span style="color: #008000">//</span>
        <span style="color: #008000">// The Page_Load event on this page is used to fetch details</span>
        <span style="color: #008000">// about the product to review.  It then updates UI elements</span>
        <span style="color: #008000">// with the results.</span>
        <span style="color: #008000">//</span>
        <span style="color: #008000">// Note that the product to review is specified using</span>
        <span style="color: #008000">// a querystring argument to the page.</span>
        <span style="color: #008000">//</span>
        <span style="color: #008000">//*******************************************************</span>
           
        <span style="color: #0000FF"><strong>private</strong></span> <span style="color: #0000FF"><strong>void</strong></span> <span style="color: #2040a0">Page_Load</span><span style="color: #4444FF">(</span><span style="color: #2040a0">object</span> <span style="color: #2040a0">sender</span>, <span style="color: #2040a0">System</span>.<span style="color: #2040a0">EventArgs</span> <span style="color: #2040a0">e</span><span style="color: #4444FF">)</span> <span style="color: #4444FF"><strong>{</strong></span>

            <span style="color: #0000FF"><strong>if</strong></span> <span style="color: #4444FF">(</span><span style="color: #2040a0">Page</span>.<span style="color: #2040a0">IsPostBack</span> <span style="color: #4444FF">!</span><span style="color: #4444FF">=</span> <span style="color: #0000FF"><strong>true</strong></span><span style="color: #4444FF">)</span> <span style="color: #4444FF"><strong>{</strong></span>

                <span style="color: #008000">// Obtain ProductID of Product to Review</span>
                <span style="color: #0000FF"><strong>int</strong></span> <span style="color: #2040a0">productID</span> <span style="color: #4444FF">=</span> <span style="color: #2040a0">Int32</span>.<span style="color: #2040a0">Parse</span><span style="color: #4444FF">(</span><span style="color: #2040a0">Request</span><span style="color: #4444FF">[</span><span style="color: #444444">&quot;productID&quot;</span><span style="color: #4444FF">]</span>, <span style="color: #2040a0">CultureInfo</span>.<span style="color: #2040a0">InvariantCulture</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
        
                <span style="color: #008000">// Populate Product Name on Page</span>
                <span style="color: #2040a0">ProductsDB</span> <span style="color: #2040a0">products</span> <span style="color: #4444FF">=</span> <span style="color: #0000FF"><strong>new</strong></span> <span style="color: #2040a0">ProductsDB</span><span style="color: #4444FF">(</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
                <span style="color: #2040a0">ModelName</span>.<span style="color: #2040a0">Text</span> <span style="color: #4444FF">=</span> <span style="color: #2040a0">products</span>.<span style="color: #2040a0">GetProductDetails</span><span style="color: #4444FF">(</span><span style="color: #2040a0">productID</span>, <span style="color: #2040a0">WorldReady</span>.<span style="color: #2040a0">CurrentLanguage</span><span style="color: #4444FF">(</span><span style="color: #4444FF">)</span><span style="color: #4444FF">)</span>.<span style="color: #2040a0">ModelName</span><span style="color: #4444FF">;</span>
            
                <span style="color: #008000">// Store ProductID in Page State to use on PostBack</span>
                <span style="color: #2040a0">ViewState</span><span style="color: #4444FF">[</span><span style="color: #444444">&quot;productID&quot;</span><span style="color: #4444FF">]</span> <span style="color: #4444FF">=</span> <span style="color: #2040a0">productID</span><span style="color: #4444FF">;</span>
            <span style="color: #4444FF"><strong>}</strong></span>
        <span style="color: #4444FF"><strong>}</strong></span>

        <span style="color: #008000">//*******************************************************</span>
        <span style="color: #008000">//</span>
        <span style="color: #008000">// The ReviewAddButton_Click event is used to add a new</span>
        <span style="color: #008000">// review into the AdventureWorks Reviews database.</span>
        <span style="color: #008000">//</span>
        <span style="color: #008000">// Note that we are deliberately HtmlEncoding all text</span>
        <span style="color: #008000">// values *before* adding them to the database.  This allows</span>
        <span style="color: #008000">// us to prevent hackers from adding images or hyperlinks</span>
        <span style="color: #008000">// into the message content.</span>
        <span style="color: #008000">//</span>
        <span style="color: #008000">//*******************************************************</span>

        <span style="color: #0000FF"><strong>protected</strong></span> <span style="color: #0000FF"><strong>void</strong></span> <span style="color: #2040a0">ReviewAddButton_Click</span><span style="color: #4444FF">(</span><span style="color: #2040a0">object</span> <span style="color: #2040a0">sender</span>, <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Web</span>.<span style="color: #2040a0">UI</span>.<span style="color: #2040a0">ImageClickEventArgs</span> <span style="color: #2040a0">e</span><span style="color: #4444FF">)</span>
        <span style="color: #4444FF"><strong>{</strong></span>

            <span style="color: #008000">// Only add the review if all fields on the page are valid</span>
            <span style="color: #0000FF"><strong>if</strong></span> <span style="color: #4444FF">(</span><span style="color: #2040a0">Page</span>.<span style="color: #2040a0">IsValid</span> <span style="color: #4444FF">=</span><span style="color: #4444FF">=</span> <span style="color: #0000FF"><strong>true</strong></span><span style="color: #4444FF">)</span> <span style="color: #4444FF"><strong>{</strong></span>
              
                <span style="color: #008000">// Obtain ProductID from Page State</span>
                <span style="color: #0000FF"><strong>int</strong></span> <span style="color: #2040a0">productID</span> <span style="color: #4444FF">=</span> <span style="color: #4444FF">(</span><span style="color: #0000FF"><strong>int</strong></span><span style="color: #4444FF">)</span> <span style="color: #2040a0">ViewState</span><span style="color: #4444FF">[</span><span style="color: #444444">&quot;productID&quot;</span><span style="color: #4444FF">]</span><span style="color: #4444FF">;</span>
            
                <span style="color: #008000">// Obtain Rating number of RadioButtonList</span>
                <span style="color: #0000FF"><strong>int</strong></span> <span style="color: #2040a0">rating</span> <span style="color: #4444FF">=</span> <span style="color: #2040a0">Int32</span>.<span style="color: #2040a0">Parse</span><span style="color: #4444FF">(</span><span style="color: #2040a0">Rating</span>.<span style="color: #2040a0">SelectedItem</span>.<span style="color: #2040a0">Value</span>, <span style="color: #2040a0">CultureInfo</span>.<span style="color: #2040a0">InvariantCulture</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
             
                <span style="color: #008000">// Add Review to ReviewsDB.  HtmlEncode before entry</span>
                <span style="color: #2040a0">ReviewsDB</span> <span style="color: #2040a0">review</span> <span style="color: #4444FF">=</span> <span style="color: #0000FF"><strong>new</strong></span> <span style="color: #2040a0">ReviewsDB</span><span style="color: #4444FF">(</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
                <span style="color: #2040a0">review</span>.<span style="color: #2040a0">AddReview</span><span style="color: #4444FF">(</span><span style="color: #2040a0">productID</span>, <span style="color: #2040a0">Server</span>.<span style="color: #2040a0">HtmlEncode</span><span style="color: #4444FF">(</span><span style="color: #2040a0">Name</span>.<span style="color: #2040a0">Text</span><span style="color: #4444FF">)</span>, <span style="color: #2040a0">Server</span>.<span style="color: #2040a0">HtmlEncode</span><span style="color: #4444FF">(</span><span style="color: #2040a0">Email</span>.<span style="color: #2040a0">Text</span><span style="color: #4444FF">)</span>, <span style="color: #2040a0">rating</span>, <span style="color: #2040a0">Server</span>.<span style="color: #2040a0">HtmlEncode</span><span style="color: #4444FF">(</span><span style="color: #2040a0">Comment</span>.<span style="color: #2040a0">Text</span><span style="color: #4444FF">)</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
              
                <span style="color: #008000">// Redirect client back to the originating product details page</span>
                <span style="color: #2040a0">Response</span>.<span style="color: #2040a0">Redirect</span><span style="color: #4444FF">(</span><span style="color: #444444">&quot;ProductDetails.aspx?ProductID=&quot;</span> <span style="color: #4444FF">+</span> <span style="color: #2040a0">productID</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
            <span style="color: #4444FF"><strong>}</strong></span>
        <span style="color: #4444FF"><strong>}</strong></span>

        <span style="color: #0000FF"><strong>private</strong></span> <span style="color: #0000FF"><strong>void</strong></span> <span style="color: #2040a0">Page_Init</span><span style="color: #4444FF">(</span><span style="color: #2040a0">object</span> <span style="color: #2040a0">sender</span>, <span style="color: #2040a0">EventArgs</span> <span style="color: #2040a0">e</span><span style="color: #4444FF">)</span> <span style="color: #4444FF"><strong>{</strong></span>
            <span style="color: #008000">//</span>
            <span style="color: #008000">// CODEGEN: This call is required by the ASP.NET Web Form Designer.</span>
            <span style="color: #008000">//</span>
            <span style="color: #2040a0">InitializeComponent</span><span style="color: #4444FF">(</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>
        <span style="color: #4444FF"><strong>}</strong></span>

<span style="color: #0000ff"><strong>		#region Web Form Designer generated code</strong></span>
        <span style="color: #008000">/// &lt;summary&gt;</span>
        <span style="color: #008000">/// Required method for Designer support - do not modify</span>
        <span style="color: #008000">/// the contents of this method with the code editor.</span>
        <span style="color: #008000">/// &lt;/summary&gt;</span>
        <span style="color: #0000FF"><strong>private</strong></span> <span style="color: #0000FF"><strong>void</strong></span> <span style="color: #2040a0">InitializeComponent</span><span style="color: #4444FF">(</span><span style="color: #4444FF">)</span> <span style="color: #4444FF"><strong>{</strong></span>    
            <span style="color: #0000FF"><strong>this</strong></span>.<span style="color: #2040a0">ReviewAddButton</span>.<span style="color: #2040a0">Click</span> <span style="color: #4444FF">+</span><span style="color: #4444FF">=</span> <span style="color: #0000FF"><strong>new</strong></span> <span style="color: #2040a0">System</span>.<span style="color: #2040a0">Web</span>.<span style="color: #2040a0">UI</span>.<span style="color: #2040a0">ImageClickEventHandler</span><span style="color: #4444FF">(</span><span style="color: #0000FF"><strong>this</strong></span>.<span style="color: #2040a0">ReviewAddButton_Click</span><span style="color: #4444FF">)</span><span style="color: #4444FF">;</span>

        <span style="color: #4444FF"><strong>}</strong></span>
<span style="color: #0000ff"><strong>		#endregion</strong></span>

    <span style="color: #4444FF"><strong>}</strong></span>
<span style="color: #4444FF"><strong>}</strong></span>

</pre>
